import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.ManagementService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.identity.UserQuery;
import org.activiti.engine.impl.persistence.entity.UserManager;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class Test {

	public static void main(String[] args) {
		String[] springXml = {"spring_core.xml", "spring_activiti.xml"};
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(springXml);
		
		RepositoryService repositoryService = (RepositoryService)context.getBean("repositoryService");
		RuntimeService runtimeService = (RuntimeService)context.getBean("runtimeService");
		TaskService taskService = (TaskService)context.getBean("taskService");
		IdentityService identityService = (IdentityService)context.getBean("identityService");
		HistoryService historyService = (HistoryService)context.getBean("historyService");
		ManagementService managementService = (ManagementService)context.getBean("managementService");
		
		//发布
//		repositoryService.createDeployment().addClasspathResource("finance.bpmn20.xml").deploy();
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("departmentName", "研发部");
		runtimeService.startProcessInstanceByKey("finance", map);
		
		//实例化一个进程
//		ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("finance");
		
		//获取工作列表
		List<Task> list = taskService.createTaskQuery().taskCandidateGroup("分析师").list();
		for(Task element: list) {
			System.out.println(element.getId() + ": " + element.getTaskDefinitionKey());
		}
		
//		Task task = taskService.createTaskQuery().processDefinitionId(processInstance.getId()).taskDefinitionKey("submitReport").singleResult();
//		taskService.addCandidateUser(task.getId(), "202");
	
//		taskService.complete("2402");
//		taskService.complete("2310");
		/*Map<String, Object> map = new HashMap<String, Object>();
		map.put("amount", 3000);
		taskService.complete(list.get(0).getId(), map);*/
		
		/*UserQuery userQuery = identityService.createUserQuery();
		long count = userQuery.count();
		System.out.println(count);*/
		
	}
}
